package com.situ.controller;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.situ.entily.User;
import com.situ.service.UserService;
import com.situ.service.impl.UserServiceImpl;
import com.situ.util.BaseController;
import com.situ.vo.LayuiTableVO;
import com.situ.vo.ResultVO;


@WebServlet("/user")
public class UserController extends BaseController {
    private static final long serialVersionUID = 1L;

    UserService service = new UserServiceImpl();


    public void page(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.getRequestDispatcher("/WEB-INF/user.jsp").forward(request, response);
    }

    public LayuiTableVO list(Integer page, Integer limit, String keyword) {
        List<User> list = service.all(page, limit, keyword);
        LayuiTableVO vo = new LayuiTableVO();
        vo.setCode(0);
        vo.setData(list);
        vo.setCount(service.count(keyword));
        return vo;
    }

    public ResultVO sel(Integer id) {

        return service.selectById1(id);

    }
    public User select(Integer id) {

        return service.selectById(id);

    }

    public ResultVO save(User u, HttpSession session, HttpServletRequest request, HttpServletResponse response) {
        ResultVO vo=service.save(u,session,request,response);
        return vo;
    }

    public void delete(Integer id) {
        service.delete(id);
    }

}
